//
//  YZLauncher.m
//  VET
//
//  Created by Lam BG on 2018/6/28.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZLauncher.h"
#import "YZUser.h"
#import "YZPersonalAPI.h"
#import "YZMainTabBarController.h"
#import "YZMainNavigationController.h"

@implementation YZLauncher

+ (BOOL)isLogined {
    
    return [[YZUser sharedInstance] getLocalUser].name.length;
}

+ (BOOL)isRegisted {
    
    return ([YZUser sharedInstance].name.length && [YZUser sharedInstance].avatar.length);
}

+ (void)jumpToMain {
    
    // 释放内存，跳转到主页
    if ([YZUser sharedInstance].avatarOriginal.length == 0) {
        
        [[YZPersonalAPI requestPersonalBaseInfo] subscribeNext:^(id  _Nullable x) {
            [[YZUser sharedInstance] storeUserToLocal:x];

        } error:^(NSError * _Nullable error) {
            [[UIApplication sharedApplication] delegate].window.rootViewController = [[YZMainTabBarController alloc] init];
        } completed:^{
            [[UIApplication sharedApplication] delegate].window.rootViewController = [[YZMainTabBarController alloc] init];
        }];
    } else {
        
        [[UIApplication sharedApplication] delegate].window.rootViewController = [[YZMainTabBarController alloc] init];
    }
    
    
//    UIViewController *vc = [[UIApplication sharedApplication] delegate].window.rootViewController;
//    if ([vc presentedViewController]) {
//
//        UIViewController *pVC = [vc presentedViewController];
//        [pVC dismissViewControllerAnimated:YES completion:^{
//
//            // 直接切换，没有过度的感觉，有点生硬
//            [[UIApplication sharedApplication] delegate].window.rootViewController = [[YZMainTabBarController alloc] init];
//        }];
//    }
}

+ (void)jumpToLaunch {
    
    // 登录注册页
    UIStoryboard *launchSB = [UIStoryboard storyboardWithName:@"YZLaunchSB" bundle:nil];
    YZMainNavigationController *nav = [[YZMainNavigationController alloc] initWithRootViewController:[launchSB instantiateViewControllerWithIdentifier:@"YZEnterVC"]];
    [[UIApplication sharedApplication] delegate].window.rootViewController = nav;
}

@end
